<style>
.tree {
  /*margin-top: 42px;*/
  border: 1px solid #d7dde4;
  /* max-height: 600px; */
}

.prodShow {
  z-index: 10000;
}
.table-limit {
  max-height: 300px;
}
</style>

<template>
<Row class="layout-content-body">
    <Card>
        <Row :gutter="16">
            <Col span="12">
            <Card>
                <p slot="title">案件信息</p>
                <Form ref="editForm" :model="additionForm" :label-width="80">
                    <Row :gutter="16">
                        <Col span="12">
                        <Form-item label="案件名称" prop="Title">
                            <Input v-model="additionForm.Title" disabled placeholder="请输入案件名称"></Input>
                        </Form-item>
                        </Col>
                        <Col span="12">
                        <Form-item label="案件编号" prop="No">
                            <Input v-model="additionForm.No" disabled placeholder="请输入案件编号"></Input>
                        </Form-item>
                        </Col>
                    </Row>
                    <FormItem label="检验类型">
                        <!-- <Select v-model="additionForm.JdType" disabled>
                      <Option v-for="item in jyType" :value="item.value" :key="item.value">{{ item.name }}</Option>
                    </Select> -->
                        <Input v-model="computedType" disabled placeholder="请输入案件编号"></Input>
                    </FormItem>
                    <FormItem label="分类">
                        <!-- <Select v-model="additionForm.Category"  disabled>
                      <Option v-for="item in jyCategory" :value="item.value" :key="item.value">{{ item.name }}</Option>
                    </Select> -->
                     <Input v-model="computedCategory" disabled placeholder="请输入案件编号"></Input>
                    </FormItem>
                    <Row :gutter="16">
                        <Col span="12">
                        <Form-item label="手机号码" prop="Phone">
                            <Input v-model="additionForm.Phone" disabled placeholder="请输入手机号码"></Input>
                        </Form-item>
                        </Col>
                        <Col span="12">
                        <FormItem label="是否初检">
                            <RadioGroup v-model="additionForm.First">
                                <Radio disabled v-for="item in chujianArray" :label="item.value" :key="item.value">{{item.name}}</Radio>
                            </RadioGroup>
                        </FormItem>
                        </Col>
                    </Row>
                </Form>
            </Card>
            </Col>
            <Col span="12">
            <Card>
                <p slot="title">检验项</p>
                <Table :columns="columns" :data="caseAll"></Table>
            </Card>
            </Col>
        </Row>
        <Row :gutter="16">
          <Col span="12">
            <Card>
                <p slot="title">预约信息</p>
                <Table :columns="approvecolumns" :data="approves" class="table-limit"></Table>
            </Card>
          </Col>
          <Col span="12">
            <Card>
                <p slot="title">检验信息</p>
                <Table :columns="todoListColumns" :data="cateItems" class="table-limit" ></Table>
            </Card>
          </Col>
        </Row>
    </Card>
    <!-- <Card>
    <p slot="title">变更明细</p>
    <Table :columns="columns" :data="dataAll" :hover-show="true"></Table>
  </Card> -->


    <Card v-if="orderData.edit">
        <p slot="title">审批意见</p>
        <Form ref="editForm" :model="approveItem" :label-width="80"  :rules="ruleValidate">
            <FormItem label="是否同意">
                <RadioGroup v-model.number="approveItem.Result">
                    <Radio :label="1">确认</Radio>
                    <Radio :label="2">驳回</Radio>
                </RadioGroup>
            </FormItem>
            <FormItem label="审批意见" >
                <Input v-model="approveItem.Opinions"  placeholder="审批意见..."></Input>
            </FormItem>
            <FormItem label="备注" >
                <Input v-model="approveItem.Remark"  type="textarea" :autosize="{minRows: 2,maxRows: 5}" placeholder="备注..."></Input>
            </FormItem>
            <FormItem>
                <Button type="primary" @click="handleSubmit('editForm')">提交</Button>
                <Button type="ghost" style="margin-left: 8px">取消</Button>
            </FormItem>
        </Form>
    </Card>
</Row>
</template>

<script>
import { getData } from '@/common/utils';
import { timeFormat } from '@/common/filter';
import dtable from '@/components/table/etable.vue'; //

import prod from '@/views/busy/prod';
import moment from 'moment';
var list = []
var item = {}
export default {
    data () {
      return {
        loading: false, // 数据刷新遮罩层
        approves: [],
        recive: [],
        current: 0,
        status: 'wait',
        approvecolumns: [
        // 多选框
          {
              title: '名称',
              key: 'Text'
          },
          {
              title: '审批人',
              key: 'Approver'
          },
          {
              title: '审批意见',
              key: 'Opinions'
          },
          {
              title: '审批状态',
              key: 'Result',
              render: (h, params) => {
              let str = '';
              if (params.row.Result === 1) {
                str = '同意';
            } else if (params.row.Result === 2) {
                str = '不同意';
            } else {
                if (params.row.Status === 1) {
                  str = '正在处理';
              } else if (params.row.Status === 2) {
                  str = '已通过';
              } else {
                  str = '未开始';
              }
            }
              return h('span', {}, str)
          }
          },
          {
              title: '审批时间',
              key: 'Atime',
              width: 160,
              render: (h, params) => {
              return h('div', [
                h('strong', timeFormat(getData(params.row.Atime)))
            ])
          }
          }
      ], // 表格样式
        columns: [
          {
              title: ' ',
              type: 'index',
              width: 30
          },
          {
              title: '物证信息',
              key: 'Remark'
          },
          {
              title: '鉴定类型',
              key: '',
              render: (h, { row }) => {
              let str = '';
              for (let i = 0; i < this.jyType.length; i++) {
                if (row.JyType == this.jyType[i].value) {
                  str = this.jyType[i].name
              }
            }
              return h('span', {}, str)
          }
          },
          {
              title: '分类',
              key: 'Category',
              render: (h, { row }) => {
              let str = '';
              for (let i = 0; i < this.jyType.length; i++) {
                if (row.JyType == this.jyType[i].value) {
                  let category = this.jyType[i].children
                for (let j = 0; j < category.length; j++) {
                    if (row.Category == category[j].value) {
                      str = category[j].name
                  }
                }
              }
            }
              return h('span', {}, str)
          }
          },
          {
              title: '预约时间',
              key: 'AppointTime',
              render: (h, {row}) => {
              let flag = row['AppointTime']
              return h('span', {}, moment(row['AppointTime']).format('YYYY-MM-DD HH:mm'))
          }
          },
          {
              title: '送件时间',
              key: 'CinTime',
              render: (h, {row}) => {
              let flag = row['Cin']
              return h('span', {}, flag == 1 ? moment(row['CinTime']).format('YYYY-MM-DD HH:mm') : '')
          }
          },
          {
              title: '送件人',
              key: 'CinUser'
          }
      ], // 表格样式
        todoType: [
        {key: 0, value: '送件'},
        {key: 1, value: '检验'},
        {key: 2, value: '完成'},
        {key: 3, value: '取件'}
      ],
        todoListColumns: [
          {
              title: ' ',
              type: 'index',
              width: 30
          },
          {
              title: '步骤',
              key: 'Type',
              render: (h, {row}) => {
              let str = ''
              for (let i = 0; i < this.todoType.length; i++) {
                if (row['Type'] == this.todoType[i].key) {
                  str = this.todoType[i].value
                  break
              }
            }
              return h('span', {}, str)
          }
          },
          {
              title: '发起时间',
              key: 'Ctime',
              width: 160,
              render: (h, {row}) => {
              return h('span', {}, moment(row['Ctime']).format('YYYY-MM-DD hh:mm'))
          }
          },
          {
              title: '结束时间',
              key: 'Utime',
              width: 160,
              render: (h, {row}) => {
              let time = moment(row['Utime']).format('YYYY-MM-DD hh:mm')
              let flag = row['Finish']
              return h('span', {}, flag == 1 ? time : '')
          }
          },
          {
              title: '操作人',
              key: 'Updater'
          },
          {
              title: '责任人',
              key: 'Finisher'
          }
      ],
        summary: {
          Name: '合计',
          Money: 0
      },
        dataAll: [], // 表格数据来源含合计
        datas: [], // 表格数据来源
        caseAll: [],
        cateItems: [],
        formItem: {
          Id: '',
          Name: '',
          CustName: '',
          Remark: '',
          Price: 0,
          DiscountPrice: 0,
          Off: 0
      }, // 数据编辑表单
        approveItem: {
          Opinions: '',
          Result: 1,
          Remark: ''
      }, // 数据编辑表单
        jyType: [
          {
              name: '痕迹',
              value: 0,
              children: [
              {
                  name: '手印',
                  value: 0
              },
              {
                  name: '足迹',
                  value: 1
              },
              {
                  name: '工具',
                  value: 2
              },
              {
                  name: '枪弹',
                  value: 3
              },
              {
                  name: '特殊',
                  value: 4
              },
              {
                  name: '爆炸',
                  value: 5
              },
              {
                  name: '其它',
                  value: 6
              }
          ]
          },
          {
              name: '法医',
              value: 1,
              children: [
              {
                  name: '尸体',
                  value: 0
              },
              {
                  name: '活体',
                  value: 1
              },
              {
                  name: '其它',
                  value: 2
              }
          ]
          },
          {
              name: 'DNA',
              value: 2,
              children: [
              {
                  name: '案件检验',
                  value: 0
              },
              {
                  name: '违法犯罪人员血样',
                  value: 1
              },
              {
                  name: '其它',
                  value: 2
              }
          ]
          },
          {
              name: '理化',
              value: 3,
              children: [
              {
                  name: '毒品',
                  value: 0
              },
              {
                  name: '毒物',
                  value: 1
              },
              {
                  name: '微量物证',
                  value: 2
              },
              {
                  name: '酒精含量',
                  value: 3
              },
              {
                  name: '其它',
                  value: 4
              }
          ]
          },
          {
              name: '文检',
              value: 4,
              children: [
              {
                  name: '笔记',
                  value: 0
              },
              {
                  name: '印章',
                  value: 1
              },
              {
                  name: '其他',
                  value: 2
              }
          ]
          },
          {
              name: '电子物证',
              value: 5,
              children: [
              {
                  name: '手机',
                  value: 0
              },
              {
                  name: '电脑',
                  value: 1
              },
              {
                  name: '存储设备',
                  value: 2
              },
              {
                  name: '其它',
                  value: 3
              }
          ]
          }
      ],
        jyCategory: [],
        flag: false,
        formItem: {
          Id: '',
          User: '',
          Phone: ''
      },
        timeList: [
          '09:00',
          '09:15',
          '09:30',
          '09:45',
          '10:00',
          '10:15',
          '10:30',
          '10:45',
          '11:00',
          '11:15',
          '11:30',
          '13:00',
          '13:15',
          '13:30',
          '13:45',
          '14:00',
          '14:15',
          '14:30',
          '14:45',
          '15:00',
          '15:15',
          '15:30',
          '15:45',
          '16:00',
          '16:15',
          '16:30'
      ],
        dateoptions: {
          disabledDate (date) {
            return date && date.valueOf() < Date.now() - 86400000
        }
      },
        chujianArray: [
          {
              name: '是',
              value: 1
          },
          {
              name: '否',
              value: 0
          }
      ],
        addid: true, // true为修改模式，false为添加模式
        salesAd: false,
        custShow: false,
        prodShow: false,
        salesShow: false,
        total: 0,
        orderData: this.$route.params.orderData,
        additionForm: {
          JdType: 0,
          Category: 0,
          First: 1,
          Phone: '',
          Date: new Date(),
          Time: '09:00',
          Info: '',
          Title: '',
          No: '',
          IsAdditional: true,
          CaseId: ''
      },
        ruleValidate: {
        //  Result: [
        //       { required: true, message: '请选择审批结果！', trigger: 'change' }
        //     ],
      }
    }
  },
    components: {
      dtable
  },
    computed: {
      jianyanleixing () {
        let str = '';
        for (let i = 0; i < this.jyType.length; i++) {
          if (this.formItem.JyType == this.jyType[i].value) {
            str = this.jyType[i].name
        }
      }
        return str
    },
      leixingxifen () {
        let str = '';
        for (let i = 0; i < this.jyType.length; i++) {
          if (this.formItem.JyType == this.jyType[i].value) {
            let category = this.jyType[i].children
          for (let j = 0; j < category.length; j++) {
              if (this.formItem.Category == category[j].value) {
                str = category[j].name
            }
          }
        }
      }
        return str
    },
      computedType () {
        for (let i = 0; i < this.jyType.length; i++) {
          if (this.jyType[i].value == this.additionForm.JyType) {
            return this.jyType[i].name
        }
      }
        return '';
    },
      computedCategory () {
        for (let i = 0; i < this.jyType.length; i++) {
          if (this.jyType[i].value == this.additionForm.JyType) {
            let items = this.jyType[i].children
          for (let j = 0; j < items.length; j++) {
              if (this.additionForm.Category == items[j].value) {
                return items[j].name
            }
          }
        }
      }
        return '';
    }
  },
    props: {},
    watch: {},
    methods: {
      getCaseSfItem (id) {
        this.$api.GetListByBusy(id).then(res => {
          if (res.code == 0) {
            this.cateItems = res.Data
        }
      })
    },
      getCaseItem (id) {
        this.$api.GetCaseItemsByCase(id).then(res => {
          if (res.code == 0) {
              this.caseAll = res.Data
          }
      })
    },
      jyTypeChange (idx) {
        console.log(idx)
      for (let i = 0; i < this.jyType.length; i++) {
          if (this.jyType[i].value == idx) {
            this.jyCategory = this.jyType[i].children
        }
      }
    },
      getResult (r, s) {
        if (r === 1) {
          return '同意';
      } else if (r === 2) {
          return '不同意';
      } else {
          if (s === 1) {
            return '正在处理';
        } else {
            return '未开始';
        }
      }
    },
      getindex (data) {
        return data + 1
    },
      foramt (t) {
        return timeFormat(getData(t))
    },
      getSummaryMoney () {
        let sum = 0
      if (this.datas) {
          for (let m in this.datas) {
            sum = sum + this.datas[m].Money
        }
      }
        return sum
    },
      getall () {
        if (!this.orderData || !this.orderData.order) {
          this.$router.push({
            name: '检验预约',
            params: {
              tab: '2'
          }
        })
        return;
      }
        this.loading = true
      this.formItem = this.orderData.order
      console.log('formItem', this.formItem)
      // 获取检验信息
      if (this.orderData.type == 1) {
          this.additionForm = this.orderData.order
        this.$api.GetStateinsByBusy(this.orderData.order.Id).then(res => {
            if (!res.error) {
              this.approves = res.Data.states
            this.current = res.Data.current
            // this.currentState=res.Data.currentState
            this.approveItem = res.Data.currentState
            this.approveItem.Result = 1
            // console.log(this.approveItem);
            // console.log(this.approves);
          } else {
              this.$Message.error(res.message)
          }
        })
        this.getCaseItem(this.orderData.order.Id)
          this.getCaseSfItem(this.orderData.order.Id)
      } else {
          let idParams = { Id: this.orderData.order['busy_id'] }
        this.$api.GetSfCaseById(idParams).then(res => {
            if (res.code == 0) {
              this.additionForm = res.Data
            this.$api.GetStateinsByBusy(this.orderData.order['busy_id']).then(res => {
                if (!res.error) {
                  this.approves = res.Data.states
                this.current = res.Data.current
                // this.currentState=res.Data.currentState
                this.approveItem = res.Data.currentState
                this.approveItem.Result = 1
                // console.log(this.approveItem);
                // console.log(this.approves);
              } else {
                  this.$Message.error(res.message)
              }
            })
          }
        })
        this.getCaseItem(this.orderData.order['busy_id'])
          this.getCaseSfItem(this.orderData.order['busy_id'])
      }
        this.jyTypeChange(this.additionForm.JdType)
      // 获取检验项

      //   this.$api.GetInstanceItem({Id: this.orderData.order.Id}).then(res => {
      //     if (!res.error) {
      //      console.log(res)
      //       this.dataAll = res.Data.sales
      //       this.recive = getData(res.Data.receiv)
      //       this.ReceivePercent()
      //       this.loading = false
      //     } else {
      //       this.$Message.error(res.message);
      //     }
      //   })
      // console.log(this.orderData.order.Id);
    },
      ReceivePercent () {
        let len = this.recive.length,
          pos = 0
      let sum = this.formItem.DiscountPrice
      while (pos < len) {
          this.recive[pos].Percent = (this.recive[pos].Money / sum) * 100
        pos += 1 //并从下个位置开始搜索
      }
        return
    },
      handleSubmit (name) {
      // console.log(name);
      // this.$refs[name].validate(valid => {
      //   if (valid) {
      //     console.log(this.approveItem);
      //     this.$api.FlowApprove(this.approveItem).then(res => {
      //       if (!res.error) {
      //         this.$Message.success(res.message);
      //         this.$router.push({
      //           name: "检验预约",
      //           params: {
      //             tab: "3"
      //           }
      //         });
      //       } else {
      //         this.$Message.error(res.message, 4);
      //       }
      //     });
      //   } else {
      //     console.log("false");
      //     this.$Messaconsole.log("false");ge.error("表单验证失败!");
      //   }
      // });
        this.$api.FlowApprove(this.approveItem).then(res => {
          if (!res.error) {
                this.$Message.success(res.message)
              this.$router.push({
                  name: '检验预约',
                  params: {
                    tab: '3'
                }
              })
            } else {
                this.$Message.error(res.message, 4)
            }
      })
    },
      handleReset (name) {}
  },
    mounted () {
      this.getall()
    // console.log(this.orderData)
  }
}
</script>
